﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections.ObjectModel;
using System.Windows.Data;
using Microsoft.Forums.OfflineStore;
using System.Windows.Threading;
using System.ComponentModel;

namespace Microsoft.Forums.ForumsClient.Models
{
    public class SubscribeToForumsDataModel : BindableObject
    {
        bool isDoneLoading;
        string filterByText;

        /// <summary>
        /// Gets or sets a value indicating whether this instance is done loading.
        /// </summary>
        /// <value>
        /// 	<c>true</c> if this instance is done loading; otherwise, <c>false</c>.
        /// </value>
        public bool IsDoneLoading
        {
            get
            {
                return isDoneLoading;
            }
            set
            {
                if (value != isDoneLoading)
                {
                    isDoneLoading = value;
                    OnPropertyChanged("IsDoneLoading");
                }
            }
        }

        /// <summary>
        /// Gets or sets the filter by text.
        /// </summary>
        /// <value>The filter by text.</value>
        public string FilterByText
        {
            get
            {
                return filterByText;
            }
            set
            {
                if (value != filterByText)
                {
                    filterByText = value;
                    OnPropertyChanged("FilterByText");
                }
            }
        }

        /// <summary>
        /// Gets or sets the active locale.
        /// </summary>
        /// <value>The active locale.</value>
        public Locale ActiveLocale
        {
            get { return LocaleCollectionView.CurrentItem as Locale; }
            set
            {
                LocaleCollectionView.MoveCurrentTo(value);
            }
        }

        /// <summary>
        /// Gets or sets the active brand.
        /// </summary>
        /// <value>The active brand.</value>
        public Brand ActiveBrand
        {
            get { return BrandsCollectionView.CurrentItem as Brand; }
            set
            {
                BrandsCollectionView.MoveCurrentTo(value);
            }
        }


        /// <summary>
        /// Gets or sets the sync from age collection.
        /// </summary>
        /// <value>The sync from age collection.</value>
        public ObservableCollection<int> SyncFromAgeCollection
        {
            get;
            private set;
        }

        /// <summary>
        /// Gets or sets the sync from age collection view.
        /// </summary>
        /// <value>The sync from age collection view.</value>
        public ListCollectionView SyncFromAgeCollectionView
        {
            get;
            private set;
        }

        /// <summary>
        /// Gets or sets the preview forums collection.
        /// </summary>
        /// <value>The preview forums collection.</value>
        public ObservableCollection<Forum> PreviewForumsCollection
        {
            get;
            private set;
        }

        /// <summary>
        /// Gets or sets the preview forums collection view.
        /// </summary>
        /// <value>The preview forums collection view.</value>
        public ListCollectionView PreviewForumsCollectionView
        {
            get;
            private set;
        }

        /// <summary>
        /// Gets or sets the brands collection.
        /// </summary>
        /// <value>The brands collection.</value>
        public ObservableCollection<Brand> BrandsCollection
        {
            get;
            private set;
        }

        /// <summary>
        /// Gets or sets the brands collection view.
        /// </summary>
        /// <value>The brands collection view.</value>
        public ListCollectionView BrandsCollectionView
        {
            get;
            private set;
        }

        /// <summary>
        /// Gets or sets the available forums collection.
        /// </summary>
        /// <value>The available forums collection.</value>
        public ObservableCollection<Forum> AvailableForumsCollection
        {
            get;
            private set;
        }

        /// <summary>
        /// Gets or sets the available forums collection view.
        /// </summary>
        /// <value>The available forums collection view.</value>
        public ListCollectionView AvailableForumsCollectionView
        {
            get;
            private set;
        }


        /// <summary>
        /// Gets or sets the locale collection.
        /// </summary>
        /// <value>The locale collection.</value>
        public ObservableCollection<Locale> LocaleCollection
        {
            get;
            set;
        }

        /// <summary>
        /// Gets or sets the locale collection view.
        /// </summary>
        /// <value>The locale collection view.</value>
        public ListCollectionView LocaleCollectionView
        {
            get;
            private set;
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="SubscribeToForumsDataModel"/> class.
        /// </summary>
        public SubscribeToForumsDataModel()
        {
            LocaleCollection = new DispatchingObservableCollection<Locale>();
            LocaleCollectionView = new ListCollectionView(LocaleCollection);
            LocaleCollectionView.SortDescriptions.Add(new SortDescription("LocaleName", ListSortDirection.Ascending));

            AvailableForumsCollection = new DispatchingObservableCollection<Forum>();
            AvailableForumsCollectionView = new ListCollectionView(AvailableForumsCollection);
            AvailableForumsCollectionView.SortDescriptions.Add(new SortDescription("DisplayName", ListSortDirection.Ascending));

            BrandsCollection = new DispatchingObservableCollection<Brand>();
            BrandsCollectionView = new ListCollectionView(BrandsCollection);
            BrandsCollectionView.SortDescriptions.Add(new SortDescription("BrandName", ListSortDirection.Ascending));

            PreviewForumsCollection = new DispatchingObservableCollection<Forum>();
            PreviewForumsCollectionView = new ListCollectionView(PreviewForumsCollection);
            PreviewForumsCollectionView.SortDescriptions.Add(new SortDescription("DisplayName", ListSortDirection.Ascending));

            SyncFromAgeCollection = new DispatchingObservableCollection<int> { 1, 7, 30, 60, 90 };
            SyncFromAgeCollectionView = new ListCollectionView(SyncFromAgeCollection);
            SyncFromAgeCollectionView.MoveCurrentTo(7);

        }



    }
}
